package com.origin.niuke.point;

/**
 * 长度为 K 的重复字符子串
 * 算法：滑动窗口
 *
 * @author yezh
 * @date 2023/1/13 23:32
 */
public class NC179 {

    public static void main(String[] args) {
        System.out.println(new NC179().numKLenSubstrRepeats("yokagames", 3));
    }

    public int numKLenSubstrRepeats(String s, int k) {
        // write code here
        int ans = 0, flag = 0;
        int[] cnts = new int[26];
        for (int i = 0; i < s.length(); i++) {
            if (++cnts[s.charAt(i) - 'a'] == 2) ++flag;
            if (i < k - 1) continue;
            if (i >= k && --cnts[s.charAt(i - k) - 'a'] == 1) --flag;
            if (flag > 0) ++ans;
        }
        return ans;
    }

}
